package com.bw.module_service.fragment

import android.app.Activity
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.lib_common.arouter.Router
import com.bw.lib_common.base.BaseFragment
import com.bw.module_service.R
import com.bw.module_service.adapter.GetSignInfoAdapter
import com.bw.module_service.databinding.FragmentAllBinding
import com.bw.module_service.viewmodel.ServiceViewModel
import dagger.hilt.android.AndroidEntryPoint


@AndroidEntryPoint
class AllFragment : BaseFragment<ServiceViewModel,FragmentAllBinding>() {
    override val mLayoutResId: Int
        get() = R.layout.fragment_all

    private val mViewModel:ServiceViewModel by viewModels()

    private lateinit var mAdapter: GetSignInfoAdapter


    private var shouldRefresh = false
    override fun initView() {
        super.initView()

    }

    override fun initData() {

        mViewModel.getSignInfo(1)
    }



    override fun initListener() {
        mViewModel.signInfoLiveData_.observe(this){
            mAdapter = GetSignInfoAdapter(
                it.filter { it.status != "1" && !it.status.isNullOrEmpty() && it.status != "2" && it.status != "0" && it.status != "超时"}.reversed(),
                onItemCLick = {
                    shouldRefresh = true
                    ARouter.getInstance().build(Router.Ui.AttendancesActivity).navigation()
                    Log.d("aaa",  "model:00000)")
                })
            mBinding.rvSign.adapter = mAdapter
            mBinding.rvSign.layoutManager = LinearLayoutManager(requireContext())
            mAdapter.notifyDataSetChanged()
        }
    }

    override fun onResume() {
        super.onResume()
        if (shouldRefresh) {
            mViewModel.getSignInfo(1)
            shouldRefresh = false
        }
    }


}